function JoinRoomViewMy() {
	thisJoinRoomViewMy = this;
	this.TAG = " < JoinRoomViewMy > ";
	
	/**
	 * 조인룸 고유 seq값 
	 */
	this.joinRoomSeq = null;
	
	/**
	 * 댓글 연동
	 */
	this.joinRoomViewMyReply = null;
	
}

JoinRoomViewMy.prototype = {
		/**
		 * 연동
		 */
		getConnectData: function() {
	    	console.log(this.TAG + "getConnectData()");
	    	
	        var mJson = new MJson();

	        mJson.putPub(MJson.PUB.SID, "JR001");
	        mJson.putPub(MJson.PUB.SERVICENAME, "getDetailJoinRoom");
	        mJson.putPub(MJson.PUB.LISTCOUNT, "3");
	        mJson.putPub(MJson.PUB.CURRPAGENO, "1");

	        mJson.putParameter(MJson.PARAMETER.JOINROOMSEQ, this.joinRoomSeq);
	        
	        var cm = new ConnectionManager();

	        cm.requestGet(mJson.getJsonString(), function(jsonData) {

	        	if(mJson.checkServiceResult(jsonData))
	        	{
	        		if( jsonData.msp.contents.items != undefined )
	        		{
	    	        	var items = jsonData.msp.contents.items; 
	    	        	var formData = new FormData(items);
	        			thisJoinRoomViewMy.initForm(formData);
	        		}
	        	}

	        }, function(e) {
	        	
	        	alert("error :: " + JSON.stringify(e));
	        	
	        });
		},
		goProfile: function($userId, $nickName) {
			console.log(this.TAG + "goProfile()");

			document.globalObj.PROFILE_DATA.userId = $userId;
			document.globalObj.PROFILE_DATA.nickName = $nickName;

			$.mobile.changePage("../mypage/profile_view.html");
		},
		init: function() {
			console.log(this.TAG + "init()");
			
			this.joinRoomSeq = document.globalObj.joinRoomSeq;
			this.getConnectData();
		},
		initEvent: function($formData) {
			console.log(this.TAG + "initEvent()");
			
			var formData = new FormData();
			formData = $formData;
			
			var joinRoomDelBtn = $("#join_room_delete_btn");
			
			joinRoomDelBtn.on("click", function($event){
				console.log(thisJoinRoomViewMy.TAG + "delete btn click!!!");
				alert("조인룸을 삭제합니다.");
				
				var deleteJoinRoom = new DeleteJoinRoom(formData.joinRoomSeq);
				deleteJoinRoom.del();
				
			});
			
			var joinRoomModifyBtn = $("#join_room_modify_btn");
			joinRoomModifyBtn.on("click", function($event){
				console.log("조인룸수정 버튼!!!!")
				document.globalObj.joinRoomModifyFormData = formData;
				
				$.mobile.changePage("join_room_modify.html");
				
			});
			
			$("#take_user_set_btn").on("click", function($event){
				console.log("참여자설정 버튼 클릭!!");
				$.mobile.changePage("join_room_person.html");
			});
		},
		initForm: function($formData) {
			console.log(this.TAG + "initForm()");
			
			var formData = new FormData();
			
			formData = $formData;
			
			if(formData != undefined)
			{
		    	/**
		    	 * 프로필
		    	 */
				console.log(formData);
				var $layer_article = $("section#join_room_view_my>section>article");
				
				var util = new Util();
				util.filePath2Url(formData.path)
				var path = util.filePath2Url(formData.path);
				$layer_article.find("img").attr("src", (formData.saveFileNm?(path+formData.saveFileNm):"../images/noimg_100_100.gif")); // .attr("src","");
				$layer_article.find("div>a>span").html(formData.nickName);
				
				$layer_article.find("div>a").on("click", function($event){
					thisJoinRoomViewMy.goProfile(formData.bookUserId, formData.nickName);
				});
				
				//..C 진행중 0 D 마감 1 E 완료 2
				var state = formData.procStatus === "C" ? 0:formData.procStatus === "D" ? 1:2;

				$layer_article.find("p:eq(0)>span").hide().eq(state).show();
				
				if(formData.openYn === "Y")
					$layer_article.find("p:eq(1)>span").hide();
				
		    	/**
		    	 * 라운드 정보
		    	 */
		    	var $layer_round_info =$("section#join_room_view_my>section>ul>li:eq(1)>ul>li");

		    	$layer_round_info.eq(0).html(formData.reserveDate + " ("+formData.bookingDay+") " + formData.bookingTime); // 일시
		    	$layer_round_info.eq(1).html(formData.golfClubInfo);
		    	$layer_round_info.eq(2).html(formData.holeInfo);
		    	
		    	/**
		    	 * 참여조건
		    	 */
		    	var $layer_take_terms =$("section#join_room_view_my>section>ul>li:eq(2)>ul>li");
		    	$layer_take_terms.eq(0).find("span").find("span").removeClass().addClass(formData.sex == "남" ? "sex_m":"sex_w").html(formData.sex); // 성별
		    	$layer_take_terms.eq(1).html("<h6>- 연령대</h6>"+formData.age+(formData.age==="" ? "":" 이상"));
		    	$layer_take_terms.eq(2).html("<h6>- 평균타수</h6>"+(function(){

		    		var avgCd = formData.avgCd;
		    		var str = "대";
		    		
		    		var rtnValue = formData.avgCd;
		    		
		    		switch(avgCd)
		    		{
		    			case 70:
		    				rtnValue = formData.avgCd+str;
		    				break;
		    			case 80:
		    				rtnValue = formData.avgCd+str;
		    				break;
		    			case 90:
		    				rtnValue = formData.avgCd+str;
		    				break;
		    			case 100:
		    				rtnValue = formData.avgCd+"돌이";
		    				break;
		    			case 99:
		    				rtnValue = "초보";
		    				break;
		    		}
		    		return rtnValue;
		    		
		    	})());
		    	
		    	$layer_take_terms.eq(3).html("<h6>- 흡연여부</h6>"+(formData.smokeYn == "Y" ? "흡연":"비흡연"));
				
		    	/**
		    	 * 신청자
		    	 */
		    	$("section#join_room_view_my>section>ul>li:eq(3)").html("<h5>신청자</h5>"+formData.applycnt+"명");
		    	/**
		    	 * 참여자
		    	 */
		    	$("section#join_room_view_my>section>ul>li:eq(4)>mark").html(formData.particnt+"명");
		    	/**
		    	 * 상세내용
		    	 */
		    	$("section#join_room_view_my>section>ul>li:eq(5)>div").html(formData.ment);
		    	
		    	/**
		    	 *  이벤트 등록
		    	 */
				this.initEvent(formData);
		    	
		    	/**
		    	 * 댓글 등록 및 리스트
		    	 */
		    	this.joinRoomViewMyReply = new JoinRoomViewMyReply(formData, this);
		    	this.joinRoomViewMyReply.init();
			}
		},
		onPageShow: function() {
			console.log(this.TAG, "onPageShow()");
			
			this.init();
		}
};



/**
 * 댓글 클래스
 */
function JoinRoomViewMyReply($formData, $context) {
	this.TAG = " < JoinRoomViewMyReply > ";
	thisJoinRoomViewMyReply = this;
	this.formData = new FormData();
	this.formData = $formData;
	this.replyList = null;
	this.context = $context;
}


JoinRoomViewMyReply.prototype = {
		constructor: JoinRoomViewMyReply,
		getReplyData: function() {
			console.log(this.TAG + "getReplyData()");
			
			this.replyList = new Array();
			var mJson = new MJson();
			
			/**
			 * JSON 구성
			 */
			mJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId	);
			mJson.putPub(MJson.PUB.SID, "JR001");
			mJson.putPub(MJson.PUB.SERVICENAME, "getReplyList");
			mJson.putPub(MJson.PUB.LISTCOUNT, "100");
			mJson.putPub(MJson.PUB.CURRPAGENO, "1");

			mJson.putParameter(MJson.PARAMETER.JOINROOMSEQ, this.formData.joinRoomSeq);
			
			/**
			 * 연동
			 */
			var cm = new ConnectionManager();
			cm.requestGet(mJson.getJsonString(), function(jsonData){
				
				//alert(JSON.stringify(jsonData));
				

							// console.log("연동:"+JSON.stringify(jsonData));

				var dummy = new DummyData();
				
				/*
				 * 모형 값 테스트
				 */
				//jsonData = dummy.getReplyList();

				
				thisJoinRoomViewMyReply.onShow(jsonData);
			
			}, function(e){
				
				alert("error :: " + JSON.stringify(e));
				
			});
			
		},
		init: function(){
			console.log(this.TAG + "init()");
			this.getReplyData();
			this.initEvent();
			
		},
		initEvent: function() {
			console.log(this.TAG + "initEvent()");
			
			/**
			 * 댓글 영역
			 */
			var $layer = $("section#join_room_view_my>section>div");
			
			/**
			 * 댓글 등록 
			 */
			var reply_area_form = $layer.find("#my_reply_text_area"); // 글쓰는 영역
			var reply_reg_btn_form = $layer.find("#my_reply_reg_btn"); // 등록 버튼
			
			/**
			 * 댓글 등록!!
			 */
			reply_reg_btn_form.on("click", function($event){
				console.log("등록 버튼 !!!");
				var content = utility.trim(reply_area_form.val());
				if(content === "")
					return alert("댓글이 입력되지 않았습니다.");

				// 등록 데이터 연동
				var myReplyRegConnect = new MyReplyRegConnect(thisJoinRoomViewMyReply.formData, content, thisJoinRoomViewMyReply);
				myReplyRegConnect.init();
			});

		},
		/**
		 * 리스트 개별 지우기
		 */
		onRemoveItem: function($id) {
			console.log(this.TAG + "onRemoveItem=" + $id);
			var id = $id;
			
			var joinRoomSeq = this.replyList[id].joinRoomSeq;
			var replySeq = this.replyList[id].replySeq;
			
			var mJson = new MJson();
			/**
			 * JSON 구성
			 */
			mJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
			mJson.putPub(MJson.PUB.SID, "JR001");
			mJson.putPub(MJson.PUB.SERVICENAME, "deleteReply");
			mJson.putPub(MJson.PUB.LISTCOUNT, "10");
			mJson.putPub(MJson.PUB.CURRPAGENO, "1");
			
			mJson.putParameter(MJson.PARAMETER.JOINROOMSEQ, joinRoomSeq);
			mJson.putParameter(MJson.PARAMETER.REPLYSEQ, replySeq);
			
			
			var cm = new ConnectionManager();
			cm.requestGet(mJson.getJsonString(), function(jsonData){
				
				console.log(thisJoinRoomViewMyReply.TAG + JSON.stringify(jsonData));
				
				thisJoinRoomViewMyReply.getReplyData();
				
			}, function(e){
				
				alert("error:"+JSON.stringify(e));
				
			})
		},
		/**
		 * 댓글 리스트
		 */
		onShow: function(jsonData) {
			
			console.log(this.TAG + "onShow()");
			
			this.replyList = null;
			this.replyList = new Array(); // 초기화
			
			var $layer_listview = $("#my_reply_listview");
			$layer_listview.empty();
			
			var totalCount = jsonData.msp.contents["@totalcount"];

			if(jsonData.msp.contents.items != undefined) {
				
				if(jsonData.msp.contents.items.length == undefined ) {
					this.replyList.push(jsonData.msp.contents.items);
				}
				else
				{
					for(var i=0; i<jsonData.msp.contents.items.length; i++) {
						this.replyList.push(jsonData.msp.contents.items[i]);
					}
				}
				


	/*			var $layer_listview = $("#reply_listview");
				$layer_listview.empty();*/
				var util = new Util();
				var list = this.replyList;

				for(var i=0; i<list.length; i++) 
				{
					var sb = new StringBuffer();
					var data = list[i];
					sb.append("<li>");
					sb.append("<a data-transition=slide><img src="+(data.saveFileNm?(util.filePath2Url(data.path)+data.saveFileNm):"../images/noimg_100_100.gif") + " alt=''/></a>");
					sb.append("<h3 id="+i+">"+(list[i].nickName === undefined ? "연동값이 없음":data.nickName)+"</h3>");
					sb.append("<p>"+data.content+"</p>");
					sb.append("<time>"+data.regDate+ " " + data.regTime + "</time>");
					sb.append("<button data-role='none' onclick=thisJoinRoomViewMyReply.onRemoveItem($(this).attr('id')) id=" + i + "><span class='ico_navi navi26'></span></button>");
					sb.append("</li>");
	
					$layer_listview.append(sb.toString());
				}

				$layer_listview.listview("refresh");
				
				/*
				 * 프로필 보기.
				 */
				$layer_listview.find("h3").unbind("click");
				$layer_listview.find("h3").bind("click", function($event){
					console.log($(this).attr("id"));
					var id = $(this).attr("id");
					var data = list[id];
					thisJoinRoomViewReply.context.goProfile(data.regId, data.nickName);
				});

			}
			
			var $reply_replyArea = $("#my_reply_area");
			$reply_replyArea.find("mark").html("("+this.replyList.length+")");
			
		}
		

}


/**
 * 댓글 등록 연동 클래스
 * @param joinRoomSeq, 댓글
 */
function MyReplyRegConnect($formData, $content, $context) 
{
	
	thisMyReplyRegConnect = this;
	this.TAG = " < ReplyRegConnect > ";
	
	this.formData = new FormData();
	this.formData = $formData;
	this.content = $content;
	this.context = $context; // joinRoomViewReply
}

MyReplyRegConnect.prototype = {

		constructor: MyReplyRegConnect,
		
		init: function(){
			console.log(this.TAG + "init()");
			var mJson = new MJson();
			
			mJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
			mJson.putPub(MJson.PUB.SID, "JR001");
			mJson.putPub(MJson.PUB.SERVICENAME, "registReply");
			mJson.putPub(MJson.PUB.LISTCOUNT, "10");
			mJson.putPub(MJson.PUB.CURRPAGENO, "1");
			
			//mJson.putClient(MJson.CLIENT.USERID, this.formData.regId);
			mJson.putParameter(MJson.PARAMETER.JOINROOMSEQ, this.formData.joinRoomSeq);
			mJson.putParameter(MJson.PARAMETER.CONTENT, this.content);
			
			//mJson.putPub(MJson.PARAMETER.REGID, this.formData.regId);
			//mJson.putPub(MJson.PARAMETER.REGID, "khs01"); // 등록자 아이디
			//mJson.putPub(MJson.PARAMETER.MODID, "khs01"); // 수정자 아이디
			//mJson.putPub(MJson.PARAMETER.REPLYSEQ, "1000"); // 댓글 시퀀스??
			
			var cm = new ConnectionManager();
			cm.requestGet(mJson.getJsonString(), function(jsonData) {
				
				console.log(jsonData);
				$("#my_reply_text_area").val("");
				
				/**
				 * 댓글 등록 및 리스트
				 */
				thisMyReplyRegConnect.context.getReplyData();
			}, function(e){
				alert("error :: " + JSON.stringify(e));
			});
		}
};

/**
 * 조인룸 삭제 클래스
 * @param $joinRoomSeq
 * @returns
 */
function DeleteJoinRoom($joinRoomSeq){
	thisDeleteJoinRoom = this;
	this.TAG = " < DeleteJoinRoom > ";
	this.joinRoomSeq = $joinRoomSeq;
}

DeleteJoinRoom.prototype = {
		del: function() {
			console.log(this.TAG + "del()");
			var mJson = new MJson();
			mJson.putPub(MJson.PUB.SID, "JR001");
			mJson.putPub(MJson.PUB.SERVICENAME, "deleteJoinRoom");
			mJson.putParameter(MJson.PARAMETER.JOINROOMSEQ, this.joinRoomSeq);
			
			var cm = new ConnectionManager();
			cm.requestGet(mJson.getJsonString(), function(jsonData){
				console.log("조인룸삭제결과:"+JSON.stringify(jsonData));
				
				if(jsonData.msp.result.code === "00000")
					$.mobile.changePage("join_room_my.html");
				else
					alert("다시 시도해주세요.");
				
			}, function(e){
				alert("error :: " + JSON.stringify(e));
			});
		}
}


